﻿using System;
using System.Collections.Generic;
using System.Data;
using nkstdgia.common.ThamDinhGia.BusinessObjects;

namespace nkstdgia.common.ThamDinhGia.DataAccess
{
    public class THONG_TIN_VI_TRIDA
    {
        #region ***** Init Methods *****

        public THONG_TIN_VI_TRIDA()
        {
        }

        #endregion ***** Init Methods *****

        #region ***** Get Methods *****

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public THONG_TIN_VI_TRI Populate(IDataReader myReader)
        {
            THONG_TIN_VI_TRI obj = new THONG_TIN_VI_TRI();
            obj.MA_HO_SO = (Int64)myReader["MA_HO_SO"];
            obj.CACH_TRUNG_TAM = myReader["CACH_TRUNG_TAM"] != DBNull.Value ? (double)myReader["CACH_TRUNG_TAM"] : 0.0;
            obj.CACH_DUONG_CHINH = myReader["CACH_DUONG_CHINH"] != DBNull.Value ? (double)myReader["CACH_DUONG_CHINH"] : 0.0;
            return obj;
        }

        /// <summary>
        /// Get THONG_TIN_VI_TRI by ma_ho_so
        /// </summary>
        /// <param name="ma_ho_so">MA_HO_SO</param>
        /// <returns>THONG_TIN_VI_TRI</returns>
        public THONG_TIN_VI_TRI GetByMA_HO_SO(Int64 ma_ho_so)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THONG_TIN_VI_TRI_GetByMA_HO_SO", Data.CreateParameter("MA_HO_SO", ma_ho_so)))
            {
                if (reader.Read())
                {
                    return Populate(reader);
                }
                return null;
            }
        }

        /// <summary>
        /// Get all of THONG_TIN_VI_TRI
        /// </summary>
        /// <returns>List<<THONG_TIN_VI_TRI>></returns>
        public List<THONG_TIN_VI_TRI> GetList()
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THONG_TIN_VI_TRI_Get"))
            {
                List<THONG_TIN_VI_TRI> list = new List<THONG_TIN_VI_TRI>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of THONG_TIN_VI_TRI
        /// </summary>
        /// <returns>DataSet</returns>
        public DataSet GetDataSet()
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THONG_TIN_VI_TRI_Get");
        }

        /// <summary>
        /// Get all of THONG_TIN_VI_TRI paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>List<<THONG_TIN_VI_TRI>></returns>
        public List<THONG_TIN_VI_TRI> GetListPaged(int recperpage, int pageindex)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THONG_TIN_VI_TRI_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex)))
            {
                List<THONG_TIN_VI_TRI> list = new List<THONG_TIN_VI_TRI>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of THONG_TIN_VI_TRI paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>DataSet</returns>
        public DataSet GetDataSetPaged(int recperpage, int pageindex)
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THONG_TIN_VI_TRI_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex));
        }

        #endregion ***** Get Methods *****

        #region ***** Add Update Delete Methods *****

        /// <summary>
        /// Add a new THONG_TIN_VI_TRI within THONG_TIN_VI_TRI database table
        /// </summary>
        /// <param name="obj">THONG_TIN_VI_TRI</param>
        /// <returns>key of table</returns>
        public long Add(THONG_TIN_VI_TRI obj)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THONG_TIN_VI_TRI_Add"
                            , Data.CreateParameter("MA_HO_SO", obj.MA_HO_SO)
                            , Data.CreateParameter("CACH_TRUNG_TAM", obj.CACH_TRUNG_TAM)
                            , Data.CreateParameter("CACH_DUONG_CHINH", obj.CACH_DUONG_CHINH)
            );
            return obj.MA_HO_SO;
        }

        /// <summary>
        /// updates the specified THONG_TIN_VI_TRI
        /// </summary>
        /// <param name="obj">THONG_TIN_VI_TRI</param>
        /// <returns></returns>
        public void Update(THONG_TIN_VI_TRI obj)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THONG_TIN_VI_TRI_Update"
                            , Data.CreateParameter("MA_HO_SO", obj.MA_HO_SO)
                            , Data.CreateParameter("CACH_TRUNG_TAM", obj.CACH_TRUNG_TAM)
                            , Data.CreateParameter("CACH_DUONG_CHINH", obj.CACH_DUONG_CHINH)
            );
        }

        /// <summary>
        /// Delete the specified THONG_TIN_VI_TRI
        /// </summary>
        /// <param name="ma_ho_so">MA_HO_SO</param>
        /// <returns></returns>
        public void Delete(Int64 ma_ho_so)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THONG_TIN_VI_TRI_Delete", Data.CreateParameter("MA_HO_SO", ma_ho_so));
        }

        #endregion ***** Add Update Delete Methods *****
    }
}